class Solution {
public:
    int removeDuplicates(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int len = 0;
        for (int i = 0; i < n; ) {
            int j = i + 1;
            while (j < n && A[j] == A[i]) {
                ++j;
            }
            A[len++] = A[i];
            i = j;
        }
        return len;

    }
};
